//
//  HaveRecJPieces.m
//
//  Created by 春程 王 on 16/8/3
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "HaveRecJPieces.h"


NSString *const kHaveRecJPiecesAreaCode = @"areaCode";
NSString *const kHaveRecJPiecesNameSender = @"nameSender";
NSString *const kHaveRecJPiecesOrderId = @"orderId";
NSString *const kHaveRecJPiecesId = @"id";
NSString *const kHaveRecJPiecesPieceCode = @"pieceCode";
NSString *const kHaveRecJPiecesPhoneSender = @"phoneSender";
NSString *const kHaveRecJPiecesAddressSender = @"addressSender";
NSString *const kHaveRecJPiecesAddressRecipient = @"addressRecipient";
NSString *const kHaveRecJPiecesTimeAdd = @"timeAdd";


@interface HaveRecJPieces ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation HaveRecJPieces

@synthesize areaCode = _areaCode;
@synthesize nameSender = _nameSender;
@synthesize orderId = _orderId;
@synthesize jPiecesIdentifier = _jPiecesIdentifier;
@synthesize pieceCode = _pieceCode;
@synthesize phoneSender = _phoneSender;
@synthesize addressSender = _addressSender;
@synthesize addressRecipient = _addressRecipient;
@synthesize timeAdd = _timeAdd;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.areaCode = [self objectOrNilForKey:kHaveRecJPiecesAreaCode fromDictionary:dict];
            self.nameSender = [self objectOrNilForKey:kHaveRecJPiecesNameSender fromDictionary:dict];
            self.orderId = [self objectOrNilForKey:kHaveRecJPiecesOrderId fromDictionary:dict];
            self.jPiecesIdentifier = [self objectOrNilForKey:kHaveRecJPiecesId fromDictionary:dict];
            self.pieceCode = [self objectOrNilForKey:kHaveRecJPiecesPieceCode fromDictionary:dict];
            self.phoneSender = [self objectOrNilForKey:kHaveRecJPiecesPhoneSender fromDictionary:dict];
            self.addressSender = [self objectOrNilForKey:kHaveRecJPiecesAddressSender fromDictionary:dict];
            self.addressRecipient = [self objectOrNilForKey:kHaveRecJPiecesAddressRecipient fromDictionary:dict];
            self.timeAdd = [self objectOrNilForKey:kHaveRecJPiecesTimeAdd fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.areaCode forKey:kHaveRecJPiecesAreaCode];
    [mutableDict setValue:self.nameSender forKey:kHaveRecJPiecesNameSender];
    [mutableDict setValue:self.orderId forKey:kHaveRecJPiecesOrderId];
    [mutableDict setValue:self.jPiecesIdentifier forKey:kHaveRecJPiecesId];
    [mutableDict setValue:self.pieceCode forKey:kHaveRecJPiecesPieceCode];
    [mutableDict setValue:self.phoneSender forKey:kHaveRecJPiecesPhoneSender];
    [mutableDict setValue:self.addressSender forKey:kHaveRecJPiecesAddressSender];
    [mutableDict setValue:self.addressRecipient forKey:kHaveRecJPiecesAddressRecipient];
    [mutableDict setValue:self.timeAdd forKey:kHaveRecJPiecesTimeAdd];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.areaCode = [aDecoder decodeObjectForKey:kHaveRecJPiecesAreaCode];
    self.nameSender = [aDecoder decodeObjectForKey:kHaveRecJPiecesNameSender];
    self.orderId = [aDecoder decodeObjectForKey:kHaveRecJPiecesOrderId];
    self.jPiecesIdentifier = [aDecoder decodeObjectForKey:kHaveRecJPiecesId];
    self.pieceCode = [aDecoder decodeObjectForKey:kHaveRecJPiecesPieceCode];
    self.phoneSender = [aDecoder decodeObjectForKey:kHaveRecJPiecesPhoneSender];
    self.addressSender = [aDecoder decodeObjectForKey:kHaveRecJPiecesAddressSender];
    self.addressRecipient = [aDecoder decodeObjectForKey:kHaveRecJPiecesAddressRecipient];
    self.timeAdd = [aDecoder decodeObjectForKey:kHaveRecJPiecesTimeAdd];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_areaCode forKey:kHaveRecJPiecesAreaCode];
    [aCoder encodeObject:_nameSender forKey:kHaveRecJPiecesNameSender];
    [aCoder encodeObject:_orderId forKey:kHaveRecJPiecesOrderId];
    [aCoder encodeObject:_jPiecesIdentifier forKey:kHaveRecJPiecesId];
    [aCoder encodeObject:_pieceCode forKey:kHaveRecJPiecesPieceCode];
    [aCoder encodeObject:_phoneSender forKey:kHaveRecJPiecesPhoneSender];
    [aCoder encodeObject:_addressSender forKey:kHaveRecJPiecesAddressSender];
    [aCoder encodeObject:_addressRecipient forKey:kHaveRecJPiecesAddressRecipient];
    [aCoder encodeObject:_timeAdd forKey:kHaveRecJPiecesTimeAdd];
}

- (id)copyWithZone:(NSZone *)zone
{
    HaveRecJPieces *copy = [[HaveRecJPieces alloc] init];
    
    if (copy) {

        copy.areaCode = [self.areaCode copyWithZone:zone];
        copy.nameSender = [self.nameSender copyWithZone:zone];
        copy.orderId = [self.orderId copyWithZone:zone];
        copy.jPiecesIdentifier = [self.jPiecesIdentifier copyWithZone:zone];
        copy.pieceCode = [self.pieceCode copyWithZone:zone];
        copy.phoneSender = [self.phoneSender copyWithZone:zone];
        copy.addressSender = [self.addressSender copyWithZone:zone];
        copy.addressRecipient = [self.addressRecipient copyWithZone:zone];
        copy.timeAdd = [self.timeAdd copyWithZone:zone];
    }
    
    return copy;
}


@end
